// src/api/mealSet.js
import axios from 'axios'

/**
 * 获取所有套餐
 * @returns {Promise<MealSet[]>}
 */
export function listMealSets() {
    return axios.get('/mealSet/list')
}

/**
 * 获取所有套餐及其对应的客户名称
 * @param {string} [name] 客户名称（可选，用于过滤）
 * @returns {Promise<MealSetWithClient[]>}
 */
export function listMealSetsWithClient(params = {}) {
    return axios.get('/mealSet/listWithClient', { params })
}

/**
 * 根据 ID 获取单个套餐
 * @param {number|string} id 套餐 ID
 * @returns {Promise<MealSet>}
 */
export function getMealSet(id) {
    return axios.get(`/mealSet/${id}`)
}

/**
 * 创建新的套餐
 * @param {Object} set MealSet 对象，字段示例：{ clientId, calendarId, notes, … }
 * @returns {Promise<void>}
 */
export function createMealSet(set) {
    return axios.post('/mealSet/create', set)
}

/**
 * 更新已有的套餐
 * @param {Object} set MealSet 对象，必须带 id，例如：{ id, clientId, calendarId, … }
 * @returns {Promise<void>}
 */
export function updateMealSet(set) {
    return axios.put('/mealSet/update', set)
}

/**
 * 删除套餐
 * @param {number|string} id 套餐 ID
 * @returns {Promise<void>}
 */
export function deleteMealSet(id) {
    return axios.delete(`/mealSet/delete/${id}`)
}

/**
 * 根据客户名称搜索套餐
 * @param {string} name 客户名称
 * @returns {Promise<MealSet[]>}
 */
export function listClientsWithoutMealSet(name = '') {
    const params = {}
    if (name) params.name = name
    return axios.get('/mealSet/listClientsWithoutMealSet', { params })
}

